{extend name="common@admin_base" /}

{block name="head_extends"}
<script>
    function examine(articleId,status,remark,table) {
        $.ajax({
            url:'{$_form.admin_articles_examine}',
            method:'post',
            data:{
                id:articleId,
                status:status,
                remark:remark
            },success:function(data){
                if (typeof data == 'string'){
                    data = JSON.parse(data);
                }
                if (data.msg == 1){
                    table.reload('articles', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                }else{
                    alert(data.info);
                }
            },error:function (err) {

            }
        });
    }

    layui.use('table', function(){
        var table = layui.table;

        //刷新按钮点击事件
        $("#search").on('click',function () {
            var useridDOM = $('#userid');
            var usernameDOM = $('#username');
            var emailDOM = $('#email');
            table.reload('articles', {
                where: { //设定异步数据接口的额外参数，任意设
                    userId: useridDOM.val()
                    ,username: usernameDOM.val()
                    ,email:emailDOM.val()
                    //…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        $('#reflash').on('click',function () {
            table.reload('articles', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //工具栏监听
        table.on('tool(articles)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                var href = '{$_form.admin_articles_art}?id=';
                layer.open({
                    id:'id'+data.id,
                    title:'文章内容',
                    area: ['1000px', '500px'],
                    offset: 'lt',
                    type: 2,
                    content: [href+data.articleId] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        url:'{$_form.admin_articles_del}',
                        data:{
                            id:data.articleId
                        },
                        method:'post',
                        success:function (data) {
                            console.log(data);
                        }
                    });
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.prompt({
                    btn: ['审核通过', '审核不通过', '取消'],
                    formType: 2,
                    value: '通过',
                    title: '审核意见',
                    area: ['400px', '175px'], //自定义文本域宽高
                    btn2:function (value, index, elem) {
                        examine(data.articleId,20,value,table);
                        layer.close(index);
                    }
                },function (value, index, elem) {
                    examine(data.articleId,99,value,table);
                    layer.close(index);
                });
//                layer.alert('审核：<br>'+ JSON.stringify(data))
            }
        });
    });
</script>

{/block}
{block name="body"}
<div class="demoTable">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="userid" id="userid" autocomplete="off">
    </div>
    标题：
    <div class="layui-inline">
        <input class="layui-input" name="username" id="title" autocomplete="off">
    </div>
    作者：
    <div class="layui-inline">
        <input class="layui-input" name="email" id="author" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload" id="search"><span class="layui-icon layui-icon-search"></span>搜索</button>
    <a id="reflash" class="layui-btn"><span class="layui-icon layui-icon-refresh"></span>刷新</a>
</div>
<table class="layui-table" lay-data="{ url:'{$_form.admin_articles_list}', id:'articles', page: {layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], groups: 1 }}" lay-filter="articles">
    <thead>
        <tr>
            <!--<th lay-data="{type:'checkbox'}">ID</th>-->
            <th lay-data="{field:'articleId', minWidth:50, sort: true,width:50}">ID</th>
            <th lay-data="{minWidth:80,width:80,templet:'#get_author'}">作者</th>
            <th lay-data="{field:'title', minWidth:80, sort: true,width:100}">标题</th>
            <th lay-data="{field:'tabloid', minWidth:150, sort: true,width:150}">文章摘要</th>
            <th lay-data="{field:'countBrowses', minWidth:60, sort: true, width:90}">浏览数</th>
            <th lay-data="{field:'countLauds', minWidth:75, sort: true,width:90}">点赞数</th>
            <th lay-data="{field:'countComments', minWidth:75, sort: true,width:90}">评论数</th>
            <th lay-data="{field:'statusText', minWidth: 80,width:80}">状态</th>
            <th lay-data="{fixed: 'right', align:'center', toolbar: '#tool'}">操作</th>
        </tr>
    </thead>
</table>

<script type="text/html" id="get_author">
    {{#  if(d.userid == 0){ }}
    未知用户
    {{#  } else { }}
    {{d.user.trueName}}
    {{#  } }}
</script>

<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" target="_blank">查看</a>
    {{# if(d.status != '99'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
    {{#  } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
{/block}